test(tracking): add integration test for imagify_after_optimize hook#1197
Open
faisalahammad wants to merge 10 commits into
Open
test(tracking): add integration test for imagify_after_optimize hook#1197faisalahammad wants to merge 10 commits into
faisalahammad wants to merge 10 commits into
Conversation
When Imagify is installed via Composer as a dependency (e.g. in Bedrock), the plugin's post-install-cmd scripts don't run, so Strauss prefixing never executes. This leaves vendor/ with unprefixed League\Container classes while code references prefixed Imagify\Dependencies\League\Container\*. Fix: Add class_alias fallbacks in inc/main.php to map unprefixed classes to prefixed namespace when needed. Works for both root package install (prefixed classes exist) and dependency install (unprefixed only). Fixes wp-media#1073
The Optimize/Restore buttons on the Edit Media page triggered a full page reload through admin-post.php, and the "Optimizing..." state never cleared until the page was reloaded manually. - Wrap the meta-box buttons in imagify-data-actions-container with data-id and data-context so the existing media-modal.js click handler can scope them. - Render the Optimize button through the button/optimize template so it carries the button-imagify-optimize class the JS binds to. - Enqueue the media-modal script and print the button/processing JS template in the footer on the attachment edition screen. Reuses the existing AJAX handlers, Imagifybeat polling and button templates. No JavaScript changes. The admin-post URLs are unchanged, so the page still works with JavaScript disabled. Fixes wp-media#434
… guards - Restore `use Imagify\Dependencies\League\Container\Container;` so bare `new Container()` resolves to the prefixed FQN in `imagify_init()`. The previous PR added `class_alias()` fallbacks but removed the `use` import, which broke namespace resolution; PHPUnit integration bootstrap fataled with 'Class "Container" not found' on every PHP matrix entry, and the same fatal killed admin render during Playwright E2E login. - Drop the `false` second arg on the three `class_exists` / `interface_exists` guards in `inc/main.php` so Composer autoload runs before the alias fallback is evaluated (CodeRabbit critical). Errors fixed: - 'Class "Container" not found' (PHPUnit integration matrix PHP 7.4 + 8.0-8.4; downstream Playwright E2E login timeout) - CodeRabbit CRITICAL: autoload disabled by `false` arg PHP 7.4+ compatible. PR Checklist still requires `# Description` section on the PR body (handled separately via gh pr edit). Refs wp-media#1196
…lection deprecation Skip 3 ImagifyUser API-dependent integration tests when IMAGIFY_TESTS_API_KEY is empty (e.g. fork PRs). These tests hit live app.imagify.io endpoint; without repo secrets they always produce WP_Error responses, failing 3 assertions. Also fix ReflectionProperty::setValue() single-arg call for static properties to avoid PHP 8.4 deprecation (risky tests). Refs wp-media#1196
Replace hard-fail expect(env).toBeTruthy() pattern with test.skip() in 4 Playwright specs that need IMAGIFY_TESTS_API_KEY. Same approach as PHPUnit's markTestSkipped in commit 16ef5ea. On fork PRs without repo secrets, these 10 tests skip instead of failing. On upstream PRs with the key, all 10 run and assert normally. Refs wp-media#1196
In-branch test.skip() in fix eb5e3ca did not halt the test when checkbox is present in DOM but hidden (no-key branch). Promote skip to top-level guard so fork PRs skip cleanly. Also add toBeVisible assertion to fail fast and informatively when checkbox is not rendered. Refs wp-media#1196
CODACY_PROJECT_TOKEN is empty on fork PRs (GitHub secret policy), causing the codacy-coverage-reporter binary to hard-fail. Gate the upload step behind a repo-name match so forks get a passing 'skipped' status while internal PRs still upload coverage. Fixes PR wp-media#1196 Code Coverage failure on fork.
Add an integration test that fires the imagify_after_optimize action and verifies the Tracking Subscriber callback runs. Resolves the coverage gap where existing tests only checked Subscriber registration with has_action() but never exercised the full hook to event chain. The test resolves the real Subscriber from the DI container, swaps the Tracking dependency for a PHPUnit mock, then fires do_action(). The mock expects track_media_optimized() to be called once with the matching process and item, proving the chain works end to end without mocking the Subscriber itself. Refs wp-media#1159
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Integration test that fires the
imagify_after_optimizehook and verifies the Tracking Subscriber callback runs end to end. Resolves the gap where existing tests only asserted registration viahas_action()without exercising the full hook-to-callback chain.Summary
Adds an integration test for the
imagify_after_optimizehook that verifies the Tracking Subscriber is invoked through the full event chain. The existingTest_GetSubscriberstest only checked that the Subscriber was registered viahas_action(), but never fired the action to confirm the callback actually runs end to end.Closes #1159
Changes
Tests/Integration/classes/Tracking/Subscriber/Test_OptimizeHookIntegration.php
Before:
No test fired
imagify_after_optimize. Subscriber registration was asserted statically only.After:
Why: Resolves the real Subscriber from the DI container and swaps only the Tracking dependency for a mock, so the Subscriber itself is not mocked. Firing
do_action()exercises the complete path: ServiceProvider registration, EventManager wiring, and the Subscriber callback. The PHPUnit mock expectation auto-verifies the delegation.Testing
Test 1: Hook fires and Subscriber callback runs
composer test-integration -- --filter="Test_OptimizeHookIntegration"Result: test passes;
track_media_optimized()is called once with the expected process and item.